package com.inspur.edp.common.expr.visitor.nullvalue;

import com.inspur.edp.common.expr.exception.ExpressException;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author lizhaorui
 * @date 2025/11/17
 * @description
 */
public class NullValueFactory {

    private final static Object lockObject = new Object();

    private static Map<String, NullValueVisitor> PROVIDER_MAP;

    public static NullValueVisitor getSpi(String type) {
        if (PROVIDER_MAP == null) {
            synchronized (lockObject) {
                if (PROVIDER_MAP == null) {
                    ConcurrentHashMap<String, NullValueVisitor> temp = new ConcurrentHashMap<>();

                    //固定的几个
                    temp.put(BooleanNullValueVisitor.KIND, new BooleanNullValueVisitor());
                    temp.put(NumberNullValueVisitor.KIND, new NumberNullValueVisitor());
                    temp.put(DefaultNullValueVisitor.KIND, new DefaultNullValueVisitor());
                    PROVIDER_MAP = temp;
                }
            }
        }
        NullValueVisitor genSpi = PROVIDER_MAP.get(type);
        if (genSpi != null) {
            return genSpi;
        } else {
            throw new ExpressException("not find field construct provider " + type);
        }
    }

}

